<script setup>
import SmallLoading from "@/components/SmallLoading.vue"
import appStore from "@/stores"
import { storeToRefs } from "pinia"

const { userinfo } = storeToRefs(appStore.userStore)

const getIcon = (name) => {
  return "fab fa-" + name
}
</script>

<template>
  <div class="profile-card">
    <SmallLoading v-if="userinfo === null"></SmallLoading>
    <div v-else>
      <img :src="userinfo.avator" class="avatar" />
      <div class="name">{{ userinfo.name }}</div>
      <div class="tagline">{{ userinfo.tag_line }}</div>

      <div class="social-links">
        <a v-for="(link, name) in userinfo.otherInfos" :href="link" target="_blank"
          ><i :class="getIcon(name)"></i
        ></a>
      </div>

      <div class="stats">
        <div class="stat-item">
          <div class="stat-number">{{ userinfo.blog_nums }}</div>
          <div class="stat-label">文章</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ userinfo.label_nums }}</div>
          <div class="stat-label">分类</div>
        </div>
        <div class="stat-item">
          <div class="stat-number">{{ userinfo.view_nums }}</div>
          <div class="stat-label">访问量</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.profile-card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--border-radius);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  padding: 30px;
  text-align: center;
  transition: var(--transition);
  overflow: hidden;
  position: relative;
}

.profile-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: rgba(var(--primary-rgb), 0.5);
}

.avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 46px;
  font-weight: bold;
  transition: transform 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: 3px solid var(--glass-border);
}

.avatar::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transform: rotate(45deg);
  transition: all 0.6s ease;
}

.avatar:hover::before {
  transform: rotate(45deg) translate(50%, 50%);
}

.day-theme .avatar {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.night-theme .avatar {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.avatar:hover {
  transform: rotateY(360deg);
}

.name {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
  font-family: "Kaiti", serif;
  position: relative;
  display: inline-block;
  padding-bottom: 8px;
}

.name::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 2px;
  background: var(--secondary);
}

.tagline {
  color: var(--gray);
  font-size: 17px;
  font-style: italic;
  margin-bottom: 20px;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 20px 0;
}

.social-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(var(--bg-darker-rgb), 0.2);
  color: var(--text);
  transition: var(--transition);
  font-size: 18px;
}

.social-links a:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-3px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-top: 20px;
}

.stat-item {
  text-align: center;
  padding: 5px;
  background: rgba(var(--bg-darker-rgb), 0.2);
  border-radius: 14px;
  transition: var(--transition);
}

.stat-item:hover {
  transform: translateY(-5px);
  background: rgba(var(--primary-rgb), 0.15);
}

.stat-number {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 5px;
}

.stat-label {
  color: var(--gray);
  font-size: 14px;
}

@media (max-width: 1100px) {
  .profile-card {
    grid-column: span 2;
  }
}
</style>
